/*
 * @Description: 
 * @Author: ml
 * @Date: 2019-12-20 15:50:15
 */
import { BaseController } from '@yhfin/biz';
export default class RiskBaseController extends BaseController {
    protected selectedFieldList: any[] = [];

    protected fixedFieldList: any[] = [];
    
    protected tableColumns: any[] = [];
    
    protected showFieldList: any[] = [];
    
    protected tableKey: number = 0;
    
    protected tableName: string = ''
    
    protected layoutDialog: boolean = false;
    
    // 布局设置
    layoutSetting() {
        this.layoutDialog = true;
    }   

    // 获取页面布局信息
    async queryLayout() {
        // this.tableLoading = true;
        const resList: any = await new Promise((resolve, reject) => {
            this.$axios('/tableLayout/query/' + this.tableName)
                .then((res: any) => {
                    resolve(res);
                })
                .catch(err => {
                    reject(err);
                });
        });
        if (resList) {
            this.selectedFieldList = JSON.parse(resList);
            // 新增固定列 考虑到该列已被存入数据库问题
            this.selectedFieldList = this.selectedFieldList.filter(item => {
                const distinctIds = this.fixedFieldList.filter(fixedFieldListItem => {
                    return fixedFieldListItem.id === item.id;
                });
                if (distinctIds.length > 0) {
                    return false;
                } else {
                    return true;
                }
            });
            this.showFieldList = this.fixedFieldList.concat(this.selectedFieldList);
            this.tableKey++;
        } else {
            this.showFieldList = this.tableColumns;
            this.selectedFieldList = this.tableColumns;
            this.tableKey++;
        }
    }
}
